home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / Xaw / xbuttonbox.c < prev    next >
C/C++ Source or Header  |  1991-01-22  |  4KB  |  143 lines

  1. /*
  2.  * This an example of how to create a composite widget with children
  3.  * The composite used is a box widget.
  4.  *
  5.  * User events are handled through callback routines.
  6.  *
  7.  * November 27, 1989 - Chris D. Peterson 
  8.  */
  9.  
  10. /*
  11.  * $XConsortium: xbuttonbox.c,v 1.19 91/01/22 19:44:22 gildea Exp $
  12.  *
  13.  * Copyright 1989 Massachusetts Institute of Technology
  14.  *
  15.  * Permission to use, copy, modify, distribute, and sell this software and its
  16.  * documentation for any purpose is hereby granted without fee, provided that
  17.  * the above copyright notice appear in all copies and that both that
  18.  * copyright notice and this permission notice appear in supporting
  19.  * documentation, and that the name of M.I.T. not be used in advertising or
  20.  * publicity pertaining to distribution of the software without specific,
  21.  * written prior permission.  M.I.T. makes no representations about the
  22.  * suitability of this software for any purpose.  It is provided "as is"
  23.  * without express or implied warranty.
  24.  *
  25.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  27.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  28.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  29.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  30.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include <X11/Intrinsic.h>
  35. #include <X11/StringDefs.h>    /* Get standard string definations. */
  36.  
  37. #include <X11/Xaw/Command.h>    
  38. #include <X11/Xaw/Label.h>    
  39. #include <X11/Xaw/Box.h>    
  40. #include <X11/Xaw/Cardinals.h>    
  41.  
  42. extern void exit();
  43.  
  44. static void Syntax();
  45. static void Quit();
  46.  
  47. String fallback_resources[] = { 
  48.     "*Command.Label:    Click the left mouse button here to quit",
  49.     NULL,
  50. };
  51.  
  52. static XrmOptionDescRec options[] = {
  53.     {"-hspace",    "*Box.hSpace",    XrmoptionSepArg,    NULL},
  54.     {"-vspace",    "*Box.vSpace",    XrmoptionSepArg,    NULL},
  55. };
  56.  
  57. main(argc, argv)
  58. int argc;
  59. char **argv;
  60. {
  61.     int i;
  62.     XtAppContext app_con;
  63.     Widget toplevel, box, command;
  64.  
  65.     toplevel = XtAppInitialize(&app_con, "Xbuttonbox",
  66.                    options, XtNumber(options),
  67.                    &argc, argv, fallback_resources,
  68.                    NULL, ZERO);
  69.  
  70.     if (argc != 1)        
  71.     Syntax(app_con, argv[0]);
  72.  
  73.     /* 
  74.      * Create a Box widget and put all children in that box widget.
  75.      * 
  76.      * Unlike the Shell widget a Box widget can accept more than one child.
  77.      * By using boxes and other composites it is possible to create an
  78.      * arbitrarily complex application with hundreds or event thousands of
  79.      * widgets.
  80.      */
  81.     
  82.     box = XtCreateManagedWidget("box", boxWidgetClass, toplevel,
  83.                 NULL, ZERO);
  84.     
  85.     /*
  86.      * Put a command widget in the box.
  87.      */
  88.  
  89.     command = XtCreateManagedWidget("command", commandWidgetClass, box,
  90.                     NULL, ZERO);
  91.     XtAddCallback(command, XtNcallback, Quit, NULL);
  92.  
  93.     /* 
  94.      * Put 10 Label widget children in the Box.
  95.      */
  96.  
  97.     for (i = 1; i <= 10; i++) {
  98.     char buf[BUFSIZ];
  99.     
  100.     sprintf(buf, "labelWidgetName%d", i * i * i * i);
  101.     command = XtCreateManagedWidget(buf, labelWidgetClass, box,
  102.                     NULL, ZERO);
  103.     }
  104.  
  105.     XtRealizeWidget(toplevel);
  106.     XtAppMainLoop(app_con);
  107. }
  108.  
  109. /*    Function Name: Quit
  110.  *    Description: This function prints a message to stdout.
  111.  *    Arguments: w - ** UNUSED **
  112.  *                 call_data - ** UNUSED **
  113.  *                 client_data - ** UNUSED **
  114.  *    Returns: none
  115.  */
  116.  
  117. static void
  118. Quit(w, client_data, call_data)
  119. Widget w;
  120. XtPointer client_data, call_data;
  121. {
  122.     XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
  123.     exit(0);
  124. }
  125.  
  126. /*    Function Name: Syntax
  127.  *    Description: Prints a the calling syntax for this function to stdout.
  128.  *    Arguments: app_con - the application context.
  129.  *                 call - the name of the application.
  130.  *    Returns: none - exits tho.
  131.  */
  132.  
  133. static void 
  134. Syntax(app_con, call)
  135. XtAppContext app_con;
  136. char *call;
  137. {
  138.     XtDestroyApplicationContext(app_con);
  139.     fprintf( stderr, "Usage: %s [ -vspace <value> ] [ -hspace <value> ]\n",
  140.         call);
  141.     exit(1);
  142. }
  143.